import time
import os
from datetime import datetime
from datetime import timedelta

def timeModel():
    # 获取当前时间
    current_time = time.localtime()
    print(current_time)
    # 改变时区
    # os.environ["TZ"] = "US"
    # time.tzset()
    # 时间戳 从1970/1/1 到现在的秒数
    print(time.time())
    # 时间格式转换 
    # time -> str
    time_str = time.strftime("%Y-%m-%d %H:%M:%S", current_time)
    print(time_str)
    # str -> time
    print(time.strptime(time_str, "%Y-%m-%d %H:%M:%S"))
    # time -> tuple
    print(tuple(current_time))
    # 时间戳 -> time
    print(time.localtime(182093890238409)) # 提供了有时区的返回值
    print(time.gmtime(182093890238409)) # 没有时区的返回值
    # time -> 时间戳
    print(time.mktime(current_time))
    # 时间运算
    tuple_time = tuple(current_time)
    new_time = time.struct_time((tuple_time[0], tuple_time[1], tuple_time[2] + 1, 0,0,0,0,0,0))
    print(new_time)
    # 时间休眠
#     time.sleep(1)
    return None

def dateTimeModel():
    # 查看时间
    today = datetime.today()
    print(today)
    print(datetime.now(tz=None)) # 指定时区查看
    print(datetime.utcnow()) # -8
    # 时间格式
    # datetime -> str
    print(today.strftime("%Y-%m-%d %H:%M:%S"))
    # str -> datetime
    print(datetime.strptime("2020/11/12 20:20:00", "%Y/%m/%d %H:%M:%S"))
    # datetime -> timetuple -> tuple
    tt = today.timetuple()
    print(f"{tt}\n{tuple(tt)}")
    # tuple -> datetime
    print(datetime(2020, 11, 20))
    # datetime -> timestamp
    print(today.timestamp())
    # timestamp -> datetime
    print(datetime.fromtimestamp(23423423434))
    # 时间运算
    print(today + timedelta(hours = 1))
    return None

def get_days(days):
    days = int(days)
    time = datetime.today()
    time += timedelta(days = days)
    return time.strftime("%Y-%m-%d")

if __name__ == "__main__":
    timeModel()
    dateTimeModel()
    print(get_days(1))